﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Server.Net
{
    class FailLoginInfo
    {
        private ArrayList failLogin;

        public FailLoginInfo()
        {
            failLogin = new ArrayList();
        }

        public int GetFailLoginTimes(string userName)
        {
            int times = 0;
            DateTime currentTime = DateTime.Now;
            for (int i = failLogin.Count - 1; i >= 0 ; i--)
            {
                if (currentTime < ((FailLogin)failLogin[i]).time.AddMinutes(1))
                {
                    if (((FailLogin)failLogin[i]).userName == userName) times++;
                }
                else
                {
                    failLogin.RemoveRange(0, i + 1);
                    return times;
                }
            }
            return times;
        }

        public void AddOne(string userName)
        {
            failLogin.Add(new FailLogin(userName, DateTime.Now));
        }
    }

    class FailLogin
    {
        internal string userName;
        internal DateTime time;

        public FailLogin(string userName, DateTime time)
        {
            this.userName = userName;
            this.time = time;
        }
    }
}
